<?php
class BanksController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventhday-Adventisth Church - Kwabrafoso: Banks";
        $in_record_data = $this->Bank->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Enter Banks";
     if($_POST){
       // pr($_POST);
        $data['Bank'] = array(
            'bankname' => $_POST['bankname'],
            'branch' => $_POST['branch'],
            'accountname' => $_POST['accountname'],
            'accounttype' => $_POST['accounttype'],
            'dateopened' => $_POST['dateopened']
        );

        if(!$this->Bank->save($data)){
            $this->Session->setFlash('Error Saving Banks');
        }else{
             $this->Session->setFlash('Banks Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Banks
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Bank');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Bank->delete($id)) 
    {
        $this->Session->setFlash('Bank Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Expenditure Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Expenditure
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Bank.id' => $record_id);
    $record = $this->Bank->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Edit Banks";
     if($_POST){
        //pr($_POST);
        $data['Bank'] = array(
            'bankname' => $_POST['bankname'],
            'branch' => $_POST['branch'],
            'accountname' => $_POST['accountname'],
            'accounttype' => $_POST['accounttype'],
            'dateopened' => $_POST['dateopened']
        );

        if(!$this->Bank->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $bank = $this->Bank->findById($id);
    if (!$bank) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('bank', $bank);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Bank.id' => $record_id);
    $record = $this->Bank->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>
